'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const dbName = event.dbName
	if (event.type == 'read') {
		let res = await db.collection(dbName).where({
			_id: event.id
		}).get()
		console.log('resss', res)
		await db.collection(dbName).where({
			_id: event.id
		}).update({
			read: res.data[0].read + 1
		})
		console.log('res', res)
		//返回数据给客户端
		return {
			msg: '查询成功',
			data: res.data[0],
			code: 200
		}
	} else if (event.type == 'detail') {
		let res = await db.collection(dbName).where({
			_id: event.id
		}).get()
		//返回数据给客户端
		return {
			code: 200,
			title: "查询成功！",
			data: res.data[0]
		}
	}


};